// 焦点图设置
<template>
  <Row>
    <Row>
      <Col span="">
      <Button type="primary" size="large" @click="modal2 = true">添加</Button>
      </Col>
    </Row>
    <br>

      <Modal v-model="modal2" title="添加焦点图" @on-ok="ok" @on-cancel="cancel">
        <Form  :model="groupActivityType" :label-width="110">
          <FormItem label="活动名称">
            <Input v-model="groupActivityType.name" placeholder="活动名称"></Input>
          </FormItem>
          <FormItem label="活动说明">
            <Input v-model="groupActivityType.description" placeholder="活动说明"></Input>
          </FormItem>
          <FormItem label="是否启用">
            <i-Switch v-model="switch1" @on-change="change" />
          </FormItem>
        </Form>
      </Modal>

 
    <Row>
      <Col span="">
      <Table border :columns="columns7" :data="data6"></Table>
      </Col>
    </Row>
  </Row>

</template>

<script type="text/ecmascript-6">
export default {
  data() {
    return {
      types:1,
      testfile: "testfile",
      switch1: false,
      list: [],
      diqu: "",
      psfs: "",
      modal2: false,
      groupActivityType: {
        name: "",
        img: "",
        status: "0",
        create_user: "root",
        description: ""
      },

      formItem: "",
      columns7: [
        {
          title: "焦点图名称",
          key: "name"
        },
        {
          title: "发布时间",
          key: "create_datetime"
        },
        {
          title: "状态",
          key: "status",
          render: (h, params) => {
            if (params.row.status == 1) {
              return "已启用";
            } else {
              return "未启用";
            }
          }
        },
        {
          title: "操作",
          key: "id",
          width: 150,
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      let _self = this;
                      $.ajax({
                        url: BASE_URL + "activitymanagement/deleteType",
                        type: "get",
                        data: {
                          id: params.row.id
                        },
                        success: function(e) {
                          console.log(e);
                          if (e) {
                            _self.getActicities();
                            _self.$Message.success("删除成功");
                          } else {
                            _self.$Message.error("删除失败");
                          }
                        }
                      });
                    }
                  }
                },
                "删除"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      let _self = this;
                      _self.types = 2;
                      $.ajax({
                        url: BASE_URL + "activitymanagement/editType",
                        type: "get",
                        data: {
                          id: params.row.id
                        },
                        success: function(e) {
                          _self.groupActivityType = e;
                          _self.modal2 = true;
                          if (e.status == 1) {
                            _self.switch1 = true;
                          } else {
                            _self.switch1 = false;
                          }
                        }
                      });
                    }
                  }
                },
                "编辑"
              )
            ]);
          }
        }
      ],
      data6: [
        {
          id: "1",
          name: "John Brown"
        }
      ]
    };
  },
  created() {
    this.getActicities();
  },
  methods: {
    getActicities: function() {
      let _self = this;
      $.ajax({
        url: BASE_URL + "activitymanagement/groupActivityTypes",
        type: "get",
        success: function(e) {
          console.log(e);
          _self.data6 = e;
        }.bind(this)
      });
    },
    files: function(event, file, fileList) {
      console.log(event, file, fileList);
    },
    change: function(switch1) {
      let _self = this;
      if (switch1) {
        _self.groupActivityType.status = "1";
      } else {
        _self.groupActivityType.status = "0";
      }
    },

    ok() {
      // this.$Message.info(this.diqu);
      console.log(this.groupActivityType);
      let _self = this;
      if(_self.types == 1){
      $.ajax({
        url: BASE_URL + "activitymanagement/saveType",
        type: "post",
        data: {
          groupActivityType: JSON.stringify(_self.groupActivityType)
        },
        success: function(data) {
          console.log(data);
          if (data) {
            _self.getActicities();
            _self.$Message.success("添加成功");
            _self.groupActivityType ={
        name: "",
        img: "",
        status: "0",
        create_user: "root",
        description: ""
      };
            _self.switch1 = false
          } else {
            _self.$Message.error("添加失败");
          }
        }
      });
      }else{
      $.ajax({
        url: BASE_URL + "activitymanagement/updateType",
        type: "get",
        data: {
          groupActivityType: JSON.stringify(_self.groupActivityType)
        },
        success: function(data) {
          console.log(data);
          if (data) {
            _self.getActicities();
            _self.$Message.success("更新成功");
            _self.groupActivityType = "";
          } else {
            _self.$Message.error("更新失败");
          }
        }
      });
      }

    },
    cancel() {
      this.$Message.info("Clicked cancel");
    }
  }
};
</script>

<style scoped >
</style>
